
import { createI18n } from "vue-i18n";
import language from "./language";
import { Local } from "@/utils/storage";
// import { GetLanguageList } from '@/api/public';
const optionss: any = [
  { value: 0, label: "47测试", url: 'prod-api', },
  { value: 1, label: "Vincent本地", url: 'vincent-api', },
  { value: 2, label: "Levi本地", url: 'Levi', },
  { value: 3, label: "garrick本地", url: 'garrick', },
];
const configs: any = Local.get("envValue") ?? 0;
window.config = {
  baseUrl: optionss.filter((l: any) => l.value === configs)[0].url
}
// window.config.baseUrl = 
const locale = createI18n({
  // locale: "zh-CN", //默认显示的语言
  locale: Local.get('localLanguage') || "en-US", //默认显示的语言
  fallbackLocale: 'en-US', // 设置后备语言
  legacy: false, //composition API
  globalInjection: true, //全局生效
  messages: language,
  // storage: {
  //   // 使用localStorage作为缓存后端
  //   prefix: 'i18n_',
  //   driver: 'localStorage',
  //   expirationTime: 24 // 缓存有效时间，单位小时
  // }
});
import { zhCN } from '@/utils/language/zh-CN';
import { arAe } from '@/utils/language/ar-AE';
import { enUs } from '@/utils/language/en-US';
const languages: any = { zhCN, arAe, enUs }
async function getLanguageList() {
  const { code, data }: any = await fetch(import.meta.env.VITE_DEV_URL + 'itf/general/open/multiple/language', { method: 'get', })
  // const { code, data }: any = await GetLanguageList({ openAuth: true })
  if (code !== 200) {
    console.error('国际化初始失败！');
    return;
  }
  data?.map((r: any) => {
    languages.zhCN = { ...zhCN, [r.charKey]: r.descZh }
    languages.arAe = { ...arAe, [r.charKey]: r.descAr }
    languages.enUs = { ...enUs, [r.charKey]: r.descEn }
  })
  const lll = Local.get("localLanguage")
  locale.global.setLocaleMessage(Local.get("localLanguage"), lll === "zh-CN" ? languages.zhCN : lll === "en-US" ? languages.enUs : languages.arAe)
  // console.log('locale.global.messages:', locale.global.messages.value);
}
// getLanguageList()
export default locale;